﻿using System;
using System.Reflection;

namespace ConsoleDemo
{
    public class TypeExample
    {
        public static void GetTypeObject()
        {
            var bc = new BaseClass();
            var dc = new DerivedClass();

            BaseClass[] bca = new BaseClass[] { bc, dc };

            foreach (var v in bca)
            {
                Type t = v.GetType();                              // Get the type.
                //Type t2 = typeof(DerivedClass);

                Console.WriteLine("Object type : {0}", t.Name);

                FieldInfo[] fi = t.GetFields();                    // Get the field information.
                foreach (var f in fi)
                    Console.WriteLine("      Field : {0}", f.Name);
                Console.WriteLine();
            }
        }
    }

    class BaseClass
    {
        public int BaseField = 0;
    }

    class DerivedClass : BaseClass
    {
        public int DerivedField = 0;
    }
}
